import base64
import io
import logging
import allure
import ddddocr
from PIL import Image


def ocr(data):
    with allure.step("ocr识别"):
        logging.info("ocr识别")
        encode_data=data.split(",")[1]
        decode_data=base64.b64decode(encode_data)

        image = Image.open(io.BytesIO(decode_data))

        image_bytes = io.BytesIO()
        image.save(image_bytes, format="png")
        image_bytes = image_bytes.getvalue()

        ocr = ddddocr.DdddOcr()
        text=ocr.classification(image_bytes)
        return text

if __name__=="__main__":
    data=""
    text=ocr(data)
    print(text)

